//网络请求
import axios from 'axios';
import AppConfig from '@/constants/AppConfig.js';

const $axios = axios;

export default function() {
	var $app_config = AppConfig();
	var $base_url = $app_config.Base_Url;
	var $post_config = $app_config.POST_Cfg;
	//作品属性、类型、地区
	var $url_get_attributeTags = $base_url + "/admin/tag/v1/getAttributeTags";
	var $url_get_groups2Atag = $base_url + "/admin/tag/v1/getGroups2Atag";
	var $url_get_entityTags2Related = $base_url + "/admin/tag/v1/getEntityTags2Related";
	var $url_relateEtags = $base_url + "/admin/tag/v1/relateEtags";
	var $url_edit_attributeTag = $base_url + "/admin/tag/v1/editAttributeTag";
	var $url_edit_group2Atag = $base_url + "/admin/tag/v1/editGroup2Atag";
	var $url_del_group2Atag = $base_url + "/admin/tag/v1/delGroup2Atag";
	var $url_edit_sorts2AtagGroup = $base_url + "/admin/tag/v1/editSorts2AtagGroup";
	var $url_del_atag = $base_url + "/admin/tag/v1/delAtag";
	var $url_edit_sorts2Atag = $base_url + "/admin/tag/v1/editSorts2Atag";
	
	return {
		getAttributeTags: function() {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_attributeTags, {
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		getGroups2Atag: function() {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_groups2Atag, {
				}, $post_config)
				.then(function(response) {
					console.log(response);
					resolve(response);
				})
				.catch(function(err) {
					reject(err);
				});
			});
		},
		getEntityTags2Related: function() {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_entityTags2Related, {
				}, $post_config)
				.then(function(response) {
					console.log(response);
					resolve(response);
				})
				.catch(function(err) {
					reject(err);
				});
			});
		},
		relateEtags: function(tags) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_relateEtags, {
					tags: tags
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editAttributeTag: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit_attributeTag, {
					atId: params.atId,
					name: params.name,
					gid: params.gid,
					bgColor: params.bgColor,
					textColor: params.textColor,
					sort: params.sort,
					type: params.type,
					stype: params.stype
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editGroup2Atag: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit_group2Atag, {
					name: params.name,
					gid: params.gid,
					sort: params.sort
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		delGroup2Atag: function(gid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_del_group2Atag, {
					gid: gid
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editSorts2AtagGroup: function(sorts) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit_sorts2AtagGroup, {
					sorts: sorts
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		del2Atag: function(atId) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_del_atag, {
					atId: atId
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editSorts2Atag: function(sorts) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit_sorts2Atag, {
					sorts: sorts
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		}
	}
}